package hlhj.com.carviewpad.utils

import android.content.Context

/**
 * Created by Never Fear   on 2019\1\16 0016.
Never More....
 */
object SPHelper {
    val IdTAG="idtag"
    val IsFirst="first"
    val Record="record"
    val Location="loaction"
    fun saveIsFirst(c:Context){
        val sp = c.getSharedPreferences(IsFirst, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putBoolean("isfirst",false)
        edit.apply()
    }
    fun getIsFirst(c: Context): Boolean {
        return c.getSharedPreferences(IsFirst,Context.MODE_PRIVATE).getBoolean("isfirst",true)
    }
    //存Id信息
    fun saveidInfo(c:Context,idJson:String){
        val sp = c.getSharedPreferences(IdTAG, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putString("id",idJson)
        edit.apply()
    }
    //取Id信息
    fun getIdInfo(c: Context): String? {
        return c.getSharedPreferences(IdTAG,Context.MODE_PRIVATE).getString("id",null)
    }
    //存记录信息
    fun saveRecord(c:Context,recordStr:String){
        val sp = c.getSharedPreferences(Record, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putString("re",recordStr)
        edit.apply()
    }
    //取记录信息
    fun getRecord(c:Context): String? {
        return c.getSharedPreferences(Record,Context.MODE_PRIVATE).getString("re","[]")
    }
    //存位置
    fun saveLocation(c:Context,loc:String){
        val sp = c.getSharedPreferences(Location, Context.MODE_PRIVATE)
        val editor = sp.edit()
        editor.putString("loc",loc)
        editor.apply()
    }
    //取位置
    fun getLocation(c:Context): String {
        val sp = c.getSharedPreferences(Location, Context.MODE_PRIVATE)
        return sp.getString("loc","")
    }
    //存时间
    val Time="time"
    fun saveStime(sTimeH:Int,stimeM:Int,eTimeH:Int,eTimeM:Int,c: Context){
        val sp = c.getSharedPreferences(Time, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putInt("sTimeH",sTimeH)
        edit.putInt("stimeM",stimeM)
        edit.putInt("eTimeH",eTimeH)
        edit.putInt("eTimeM",eTimeM)
        edit.apply()
    }
    //取时间
    fun getStimeH(c:Context): Int {
        return c.getSharedPreferences(Time,Context.MODE_PRIVATE).getInt("sTimeH",0)
    }
    fun getStimeM(c:Context): Int {
        return c.getSharedPreferences(Time,Context.MODE_PRIVATE).getInt("stimeM",0)
    }
    fun getEtimeH(c:Context): Int {
        return c.getSharedPreferences(Time,Context.MODE_PRIVATE).getInt("eTimeH",0)
    }
    fun getEtimeM(c:Context): Int {
        return c.getSharedPreferences(Time,Context.MODE_PRIVATE).getInt("eTimeM",0)
    }
}